package org.lsy.k8s_assignment.controller;

import lombok.extern.slf4j.Slf4j;
import org.lsy.k8s_assignment.model.Student;
import org.lsy.k8s_assignment.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author SHIYUAN
 * @version 1.0
 */
@RestController
@Slf4j
public class StudentController {

    private final StudentService service;

    @Autowired
    StudentController(StudentService service) {
        this.service = service;
    }

    @GetMapping("findAll")
    public List<Student> findAll() {
        log.info("查找全部学生");
        return service.findAll();
    }

    @PostMapping("save")
    public boolean save(@RequestBody Student student) {
        log.info("保存学生，参数:{}", student);
        return service.saveStudent(student);
    }

    @PostMapping("update/{id}/{age}")
    public boolean update(@PathVariable Integer id, @PathVariable Integer age) {
        log.info("更新学生信息，参数:{},{}", id, age);
        return service.updateStudent(id, age);
    }

    @PostMapping("delete/{id}")
    public boolean delete(@PathVariable Integer id) {
        log.info("删除学生信息，参数:{}", id);
        return service.deleteStudent(id);
    }
}
